﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Tron.DataStructures;

namespace Tron.Players.Simple
{
    static class SimplePlayerHelper
    {
        /// <summary>
        /// Returns the move directions that are possible from the input position.
        /// </summary>
        public static List<Vector2> GetPossibleDirectionsFromPosition(int[,] board, Vector2 position)
        {
            List<Vector2> possibleDirections = new List<Vector2>();

            foreach (Vector2 directionVector in Constants.PossibleMoveDirections)
            {
                Vector2 nextPosition = position + directionVector;
                try
                {
                    if (board[(int)nextPosition.X, (int)nextPosition.Y] == -2)
                    {
                        possibleDirections.Add(directionVector);
                    }
                }
                catch (Exception)
                { }
            }
            return possibleDirections;
        }

        /// <summary>
        /// Returns the move directions that are possible from the input position, including includePosition even if it is a wall.
        /// </summary>
        public static List<Vector2> GetPossibleDirectionsFromPositionIncludingInputPositionEvenIfItIsAWall(int[,] board, Vector2 position, Vector2 includePosition)
        {
            List<Vector2> possibleDirections = new List<Vector2>();

            foreach (Vector2 directionVector in Constants.PossibleMoveDirections)
            {
                Vector2 nextPosition = position + directionVector;
                try
                {
                    if (board[(int)nextPosition.X, (int)nextPosition.Y] == -2 || nextPosition == includePosition)
                    {
                        possibleDirections.Add(directionVector);
                    }
                }
                catch (Exception)
                { }
            }
            return possibleDirections;
        }
    }
}
